package iot.ht.controller.htrole;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import iot.core.annotation.Auth;
import iot.core.annotation.Log;
import iot.core.data.BasePageDTQto;
import iot.core.data.IdNameDto;
import iot.core.data.PageData;
import iot.core.data.BaseQto;
import iot.core.enums.AuthType;
import iot.ht.controller.htrole.data.HTRoleDto;
import iot.ht.controller.htrole.service.IHTRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/htrole")
@Tag(name = "角色管理", description = "")
public class HTRoleController {
    @Autowired
    IHTRoleService ihtRoleService;

    @Auth(authType = AuthType.Login)
    @Log(logNeed = false,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/insertinit")
    @Operation(summary = "插入角色初始化", description = "")
    public HTRoleDto insertInit( )   {
         return  ihtRoleService.InsertInit();
    }



    @Auth(authType = AuthType.Login)
    @Log(logNeed = false,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/detail")
    @Operation(summary = "角色详情", description = "")
    public HTRoleDto detail(@RequestBody BaseQto mm){
        return ihtRoleService.Detail(mm);
    }

    @Auth(authType = AuthType.Auth)
    @Log(logNeed = true,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/insert")
    @Operation(summary = "新增角色", description = "")
    public  int Insert(@RequestBody HTRoleDto mm){
        return ihtRoleService.Insert(mm);
    }


    @Auth(authType = AuthType.Auth)
    @Log(logNeed = true,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/update")
    @Operation(summary = "修改角色", description = "")
    public  int Update(@RequestBody HTRoleDto mm){
        return ihtRoleService.Update(mm);
    }


    @Auth(authType = AuthType.Auth)
    @Log(logNeed = true,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/delete")
    @Operation(summary = "删除角色", description = "")
    public  int Delete(@RequestBody BaseQto mm){
        return ihtRoleService.delete(mm);
    }


    @Auth(authType = AuthType.Login)
    @Log(logNeed = false,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/page")
    @Operation(summary = "操作日志分页", description = "")
    public PageData<HTRoleDto> page(@RequestBody BasePageDTQto qm) throws Exception {

        var r=ihtRoleService.Page(  qm );
        return r;
    }

    @Auth(authType = AuthType.Login)
    @Log(logNeed = true,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/listbydept_id")
    @Operation(summary = "根据部门获取角色", description = "")
    public List<IdNameDto> ListByDept_Id(@RequestBody BaseQto mm){
        return ihtRoleService.ListByDept_Id(mm  );
    }




}
